extends Area2D

@onready var player = get_tree().get_first_node_in_group("Player")
@onready var coins_storage = get_tree().get_first_node_in_group("CoinsStorage")
@onready var animation = $AnimationPlayer

func _unhandled_key_input(event: InputEvent) -> void:
	if event.keycode == KEY_E:
		if overlaps_body(player):
			grab_coins()
			if coins_storage.get_child_count() == 0:
				EventBus.level_completed.emit()

func grab_coins() -> void:
	player.set_coin_count(0)

func show_interaction_prompt(_body: Node2D) -> void:
	EventBus.show_interaction_prompt.emit()
	animation.play("Open")
	

func hide_interaction_prompt(_body: Node2D) -> void:
	EventBus.hide_interaction_prompt.emit()
	animation.play_backwards("Open")
